
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Kafka中有那些选举机制？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Kafka中有那些选举机制？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Kafka中包含哪两种关键的选举机制？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在Kafka中，主要涉及两个关键的选举机制：Broker的Leader选举和Controller的选举。这两个机制保障了Kafka集群在面对节点故障等情况时能够可靠地进行Leader的选择。</div>
          </div>
          <div class="card-source">来源: 文档引言部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在Kafka中，是什么事件触发了Broker分区的Leader选举过程？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当一个Follower Broker通过心跳检测等方式发现Leader不可用时，它会向Controller提出选举请求，从而触发Leader选举过程。</div>
          </div>
          <div class="card-source">来源: 文档中「1、Broker的Leader选举」部分的「Leader失效检测」和「Follower提出选举请求」</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在选举新的Broker Leader时，Controller会依据哪些标准进行选择？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Controller会根据请求选举的Follower的元数据信息（如副本信息、日志最新偏移量等）来选择新的Leader。通常，选择标准是具有最新日志并且网络延迟最小的Follower。</div>
          </div>
          <div class="card-source">来源: 文档中「1、Broker的Leader选举」部分的「Leader的选择」</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Kafka集群中的Controller节点主要承担哪些职责？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Controller负责管理整个集群中所有分区和副本的状态。其主要职责包括：1. 当分区leader副本故障时，负责选举新的leader；2. 当分区的ISR集合变化时，通知所有broker更新元数据；3. 当增加topic分区时，负责分区的重新分配。</div>
          </div>
          <div class="card-source">来源: 文档中「3、Kafka的Controller有什么作用」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Kafka的Controller选举如何利用ZooKeeper来保证选举的公平性和一致性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Controller选举利用了ZooKeeper的分布式锁和顺序节点机制。希望成为Controller的Broker会在ZooKeeper上创建一个临时有序节点，而创建的节点中顺序号最小的那个Broker将成为新的Controller，这确保了选举的公平和一致。</div>
          </div>
          <div class="card-source">来源: 文档中「2、Controller选举」部分的「ZooKeeper的选举机制」和「ZooKeeper的顺序节点」</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在新的分区Leader被选出后，为什么要更新ISR（In-Sync Replicas）列表？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">更新ISR列表是为了确保有一组与新Leader保持同步状态的副本。这保证了在Leader再次失效时，仍有足够的副本具备最新数据，从而提高系统的可用性和数据的一致性。</div>
          </div>
          <div class="card-source">来源: 文档中「1、Broker的Leader选举」部分的「ISR的更新」</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">简述ZooKeeper在Kafka的两种选举机制中扮演的核心角色。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">ZooKeeper提供分布式协调服务。它通过分布式锁、有序节点和强一致性等特性，确保集群中只有一个Controller，并协调Broker的Leader选举过程，从而保障了整个选举过程的可靠性和稳定性。</div>
          </div>
          <div class="card-source">来源: 文档中「ZooKeeper在Leader选举中的作用」和「ZooKeeper在Controller选举中的作用」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">当一个Follower发起Broker Leader选举请求后，该请求是如何在集群中传播并被处理的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">选举请求会通过ZooKeeper在集群中传播。该请求会通知所有的Broker，并触发Controller，由Controller来协调各个Broker，并根据元数据信息选择新的Leader。</div>
          </div>
          <div class="card-source">来源: 文档中「1、Broker的Leader选举」部分的「选举请求的传播」和「Leader的选择」</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在Controller选举过程中，一个Broker如何最终确认自己成功当选为新的Controller？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">参与选举的Broker会检查ZooKeeper上创建的临时有序节点的顺序。只有创建了最小顺序节点的那个Broker，才能确认自己成为了新的Controller。</div>
          </div>
          <div class="card-source">来源: 文档中「2、Controller选举」部分的「新Controller的确认」</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
